<?
include('seguridad.php');
include('bd.php');
Conectar();
include ("calendario/calendario.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> BideYoday </TITLE>
  <META NAME="Generator" CONTENT="DILAPER">
  <META NAME="Author" CONTENT="Power by Sebastian Costa - Design: Nadia De Cinti">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <link href="../style.css" rel="stylesheet" type="text/css">
  <script language="JavaScript" src="calendario/javascripts.js"></script>
  <script src="../js/botonera.js" type="text/javascript"></script>
  <script language="JavaScript" type="text/JavaScript">

function validar_coment(form)
{
	if(form.nombre.value == '') {
		alert("Por favor ingresa el nombre de la promocion");
		form.nombre.focus();
		return false;
	}
	if(form.text.value == '') {
		alert("Por favor describa la promocion");
		form.text.focus();
		return false;
	}
	if(form.fecha1.value == '') {
		alert("Por favor defina la fecha de inicio");
		form.fecha1.focus();
		return false;
	}
	if(form.fecha2.value == '') {
		alert("Por favor defina la fecha de finalizasion");
		form.fecha2.focus();
		return false;
	}
		
	document.getElementById('promotions').submit();
}
</script>
 </HEAD>

 <BODY topmargin="0">
<center>
<table width="990" height="100%" cellspacing="0" cellpadding="0" class="fondo" border="0">
	<tr>
		<td width="100%" height="100%" align="center" valign="top">
			<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td align="center" valign="top">
<div style="height: 135px"></div>
<!-- contenido -->
<table width="800"  border="0" class="admin_area" cellspacing="0" cellpadding="0">
	<tr bgcolor="#ffffff">
		<td align="right" height="30">
Welcome <?echo $_SESSION['usuario'];?>&nbsp;|&nbsp;<a href="salir.php"><font color="red">Log Out</font></a>&nbsp;&nbsp;
		</td>
	</tr>	
	<tr><td height="3"></td></tr>
	<tr bgcolor="#ffffff">
		<td align="right" height="50">
<?include('menu.php');?>
		</td>
	</tr>	
	<tr><td height="3"></td></tr>
	<tr bgcolor="#ffffff">
		<td align="left" valign="top" height="300"  class="tabla_central">
<div style="margin: 10px">
<b><span class="titulo_admin">Promotions</span></b><br>
<br>
On this screen you can view, create or modify the promotions / offers.<br>
<br>
<table width="100%" border="0"class="tabla_central">
	<tr>
		<td width="45%" valign="top">
<br>
<b>List of Promotions</b><br>
<br>
If to this date with green fund, The promotion this date<br>
If to this date with red fund the this defeated promotion<br>
<br>
<table width="100%" border="0" class="tabla_admin">
	<tr>
		<td align="center" bgcolor="#ffffff">
<b>Name</b>
		</td>
		<td align="center" bgcolor="#ffffff">
<b>Start</b>
		</td>
		<td align="center" bgcolor="#ffffff">
<b>End</b>
		</td>
		<td align="center" bgcolor="#ffffff">
<b>Actions</b>
		</td>
	</tr>
<?
$result=mysql_query("SELECT * FROM promotions ORDER BY fin DESC");
$w=1;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
	if($bg_num%2==0){
$bg='bgcolor="#B4B4B4"';
}else{
$bg='bgcolor="#DDDDDD"';}
?>
	<tr id="d_<?echo$w;?>">
		<td align="center" <?echo$bg;?>>
<?echo$row[nombre];?>
		</td>
		<td align="center" <?if(date('Y-m-d')<=$row[fin]){echo'bgcolor="green"';}else{echo$bg;}?>>
<?echo$row[inicio];?>
		</td>
		<td align="center" <?if(date('Y-m-d')>=$row[fin]){echo'bgcolor="red"';}else{echo$bg;}?>>
<?echo$row[fin];?>
		</td>
		<td align="center"  <?if($row[estado]!='yes'){echo'bgcolor="red"';}else{echo'bgcolor="green"';}?> onclick="document.getElementById('m_<?echo$w;?>').style.display = 'table-row'; document.getElementById('d_<?echo$w;?>').style.display = 'none'" style="cursor: pointer">
<span>Edit</span>
		</td>
	</tr>

<form name="m_f_<?echo$w;?>" method="POST" action="acciones/promotions_edit.php">
<tr id="m_<?echo$w;?>" style="display: none">
		<td align="center" <?echo$bg;?> colspan="4">
<input type="hidden" name="id" value="<?echo$row[id];?>">
	<table width="100%" border="0" class="tabla_admin">
		<tr>
			<td width="40%" align="right">
Name&nbsp;
			</td>
			<td width="60%">
<?echo$row[nombre];?>
			</td>
		</tr>
		<tr>
			<td width="40%" align="right">
Activation Code&nbsp;
			</td>
			<td width="60%">
<input type="text" name="activacion" value="<?echo$row[activacion];?>">
			</td>
		</tr>
		<tr>
			<td width="40%" align="right">
Start&nbsp;
			</td>
			<td width="60%">
<?echo$row[inicio];?>
			</td>
		</tr>
		<tr>
			<td width="40%" align="right">
End&nbsp;
			</td>
			<td width="60%">
<?echo$row[fin];?>
			</td>
		</tr>
		<tr>
			<td width="40%" align="right">
Description&nbsp;
			</td>
			<td width="60%">
<textarea name="text"><?echo$row[texto];?></textarea>
			</td>
		</tr>
		<tr <?if($row[estado]!='yes'){echo'bgcolor="red"';}else{echo'bgcolor="green"';}?>>
			<td width="40%" align="right">
Activate&nbsp;
<?if($row[estado]=='yes'){$checked='checked';}?>
<input type="checkbox" name="estado" value="yes" <?echo$checked?>>
			</td>
			<td width="60%" align="right" <?echo$bg;?>>
Delete&nbsp;<input type="checkbox" name="borrar" value="yes">
<input type="Submit" value="Edit" style="cursor: pointer;">&nbsp;&nbsp;
<span style="cursor: pointer;" onclick="document.getElementById('m_<?echo$w;?>').style.display = 'none'; document.getElementById('d_<?echo$w;?>').style.display = 'table-row'">close edit</span>&nbsp;&nbsp;
			</td>
		</tr>
		<tr><td colspan="2" height="10"></td></tr>
	</table>
		</td>
	</tr>
</form>

<?$bg_num++;
$w++;}?>
</table>
		</td>
		<td width="10%"></td>
		<td width="45%" valign="top">
<br>
<b>To define New Promotion</b><br>
<br>
<form id="promotions" name="fcalen" method="POST" action="acciones/promotions_save.php">
	<table width="100%" border="0" class="admin_area">
		<tr>
			<td align="right" width="50%" bgcolor="#ffffff">
Name&nbsp;
			</td>
			<td width="50%">
<input type="text" name="nombre">
			</td>
		</tr>
		<tr>
			<td align="right" width="50%" bgcolor="#ffffff">
Activation Code&nbsp;
			</td>
			<td width="50%">
<input type="text" name="activacion">
			</td>
		</tr>
		<tr>
			<td align="right" valign="top" bgcolor="#ffffff">
Description&nbsp;
			</td>
			<td>
<textarea name="text"></textarea>
			</td>
		</tr>
		<tr>
			<td align="right" width="50%" bgcolor="#ffffff">
Value&nbsp;
			</td>
			<td width="50%">
$<input type="text" name="costo_d" size="4">,
<input type="text" name="costo_c" size="4" value="00">
			</td>
		</tr>
		<tr>
			<td align="right" width="250" bgcolor="#ffffff">
Start&nbsp;
			</td>
			<td>
<?
escribe_formulario_fecha_vacio("fecha1","fcalen");
?>
			</td>
		</tr>
		<tr>
			<td align="right" width="250" bgcolor="#ffffff">
End&nbsp;
			</td>
			<td>
<?
escribe_formulario_fecha_vacio("fecha2","fcalen");
?>
			</td>
		</tr>
		<tr>
			<td colspan="2" bgcolor="#ffffff" align="center">
<input type="button" value="To modify" class="form_btn" onClick="javascript:validar_coment(document.getElementById('promotions'));">
			</td>
		</tr>
	</table>
</form>
		</td>
	</tr>
</table>

</div>
<br>
		</td>
	</tr>
</table>
<table width="800" border="0" class="admin_area" cellspacing="0" cellpadding="0">
	<tr>
		<td height="3">

		</td>
	</tr>
	<tr bgcolor="#ffffff">
		<td align="right">
<?include('inc/foot.php');?>
		</td>
	</tr>
</table>
<!-- fin contenido -->
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</center>
 </BODY>
</HTML>
<?Desconectar();?>